import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)


// 阻止多次点击的时候报错
const originalPush = Router.prototype.push
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err)
}


/* Layout */
import Layout from '@/layout'
export const constantRoutes = [{
        path: '/login',
        component: () =>
            import ('@/views/login/index'),
        hidden: true
    },

    {
        path: '/404',
        component: () =>
            import ('@/views/404'),
        hidden: true
    },

    // 一级
    {
        path: '/',
        component: Layout,
        redirect: '/home',
        children: [{
            path: 'home',
            name: 'Home',
            component: () =>
                import ('@/views/home'),
            meta: { title: '首页', icon: 'iconfont icon-shouye' }
        }]
    },
    // 二级
    {
        path: '/move',
        component: Layout,
        redirect: '/move/menu/menu-1',
        name: 'move',
        meta: {
            title: '系统管理',
            icon: 'el-icon-star-on'
        },
        children: [
            // 三级
            {
                path: 'menu',
                component: () =>
                    import ('@/views/move/menu'),
                redirect: '/move/menu/menu-1',
                name: 'menu',
                meta: {
                    title: '用户'
                },
                children: [
                    {
                        path: 'menu-1',
                        name: 'menu-1',
                        component: () =>
                            import ('@/views/move/menu/menu'),
                        meta: {
                            title: '管理员用户',
                            icon: 'el-icon-star-on'
                        }
                    },
                    {
                        path: 'menut',
                        name: 'menut',
                        component: () =>
                            import ('@/views/move/menu/menut'),
                        meta: {
                            title: '普通用户',
                            icon: 'el-icon-star-on'
                        }
                    },
                ]
            },
            {
                path: 'moves',
                name: 'moves',
                component: () =>
                    import ('@/views/move'),
                meta: {
                    title: '食材列表',
                    icon: 'el-icon-star-on'
                }
            },
        ]
    },
    {
        path: '/Article',
        component: Layout,
        redirect: '/Article/Articlefl',
        meta: {
            title: '菜品管理',
            icon: 'el-icon-star-on'
        },
        children: [
            {
                path: 'food',
                name: 'articleFood',
                component: () =>
                    import ('@/views/Article/ArticleFood'),
                meta: {
                    title: '官方推荐',
                    icon: 'el-icon-star-on'
                }
            },
            {

                path: 'Announcement',
                name: 'Announcement',
                component: () =>
                    import ('@/views/Article/Announcement'),
                meta: {
                    title: '轮播图管理',
                    icon: 'el-icon-star-on'
                }
            },

            {
                path: 'Articlelist',
                name: 'Articlelist',
                component: () =>
                    import ('@/views/Article/Articlelist'),
                meta: {
                    title: '菜谱列表',
                    icon: 'el-icon-star-on'
                }
            },
        ]
    },
    // {
    //     path: '/order',
    //     component: Layout,
    //     redirect: '/Article/Articlefl',
    //     meta: {
    //         title: '订单管理',
    //         icon: 'el-icon-star-on'
    //     },
    //     children: [{
    //             path: 'orderlist',
    //             name: 'orderlist',
    //             component: () =>
    //                 import ('@/views/order/orderlist'),
    //             meta: {
    //                 title: '订单列表',
    //                 icon: 'el-icon-star-on'
    //             }
    //         },
    //         {
    //             path: 'refundorder',
    //             name: 'refundorder',
    //             component: () =>
    //                 import ('@/views/order/refundorder'),
    //             meta: {
    //                 title: '退款订单',
    //                 icon: 'el-icon-star-on'
    //             }
    //         },
    //
    //     ]
    // },
    // {
    //     path: '/member',
    //     component: Layout,
    //     redirect: '/member/membergrade',
    //     meta: {
    //         title: '会员管理',
    //         icon: 'el-icon-star-on'
    //     },
    //     children: [{
    //             path: 'membergrade',
    //             name: 'membergrade',
    //             component: () =>
    //                 import ('@/views/member/membergrade'),
    //             meta: {
    //                 title: '会员等级',
    //                 icon: 'el-icon-star-on'
    //             }
    //         },
    //         {
    //             path: 'memberlist',
    //             name: 'memberlist',
    //             component: () =>
    //                 import ('@/views/member/memberlist'),
    //             meta: {
    //                 title: '会员列表',
    //                 icon: 'el-icon-star-on'
    //             }
    //         },
    //
    //     ]
    // },
    {
        path: '/Contribution',
        component: Layout,
        redirect: '/Contribution/Contributionlist',
        // meta: {
        //     title: '投稿管理',
        //     icon: 'el-icon-star-on'
        // },
        children: [
            // {
            //     path: 'labelfl',
            //     name: 'labelfl',
            //     component: () =>
            //         import ('@/views/Contribution/labelfl'),
            //     meta: {
            //         title: '标签分类',
            //         icon: 'el-icon-star-on'
            //     }
            // },
            {
                path: 'Contributionlist',
                name: 'Contributionlist',
                component: () =>
                    import ('@/views/Contribution/Contributionlist'),
                meta: {
                    title: '投稿管理',
                    icon: 'el-icon-star-on'
                }
            },

        ]
    },

    //用户管理
    {
        path: '/mother/login',
        component: () =>
            import ('@/views/AMother/Login'),
        hidden: true
    },
    {
        path: '/mother/regist',
        component: () =>
            import ('@/views/AMother/Regist'),
        hidden: true
    },

    {
        path: '/mother',
        component: () =>
            import ('@/views/AMother/Home'),
        redirect:'/mother/mainpage',
        hidden: true,
        children: [
            //主题页面
            {
                path:'mainpage',
                name:'Mainpage',
                component:()=> import('@/views/AMother/Mainpage'),
                redirect: '/mother/mainpage/announcementArticleOfHomeView',
                children:[
                    {
                        path:'recomandArticleOfHomeView',
                        name:'RecomandArticleOfHomeView',
                        component: ()=> import("../views/AMother/recomandArticleOfHomeView"),
                    },
                    {
                        path:'announcementArticleOfHomeView',
                        name:'AnnouncementArticleOfHomeView',
                        component:()=>import("@/views/AMother/PersonalView/AnnouncementArticleOfHomeView")
                    }
                ]
            },

            //食材列表页面
            {
                path:'resourceDownload',
                name:'ResourceDownload',
                component: ()=> import('@/views/AMother/ResourceDownload'),
            },

            //食材详细页面
            {
                path:'foodDetails',
                name:'FoodDetails',
                component: ()=> import('@/views/AMother/FoodDetails'),
            },

            //个人中心界面
            {
                path: 'personalCenter',
                name: 'PersonalCenter',
                component: () => import(/* webpackChunkName: "about" */ '@/views/AMother/PersonalCenter.vue'),
                children: [
                    {
                        path:'newArticleOfPersonal',
                        name:'NewArticleOfPersonal',
                        component: ()=> import("../views/AMother/PersonalView/NewArticle"),
                    },
                    {
                        path:'newResoucesView',
                        name:'NewResoucesView',
                        component: ()=> import("../views/AMother/PersonalView/NewResoucesView.vue"),
                    },
                    {
                        path:'personalCollectView',
                        name:'PersonalCollectView',
                        component: ()=> import("../views/AMother/PersonalView/PersonalCollectView"),
                    },
                ]
            },


            //用户信息界面
            {
                path:'editMaterial',
                name:'EditMaterials',
                component:()=>
                    import('@/views/AMother/EditMaterials'),
                redirect: '/mother/editMaterial/userInforEdit',
                children: [
                    {
                        path: 'userInforEdit',
                        name: 'UserInforEdit',
                        component: () => import('@/views/AMother/EditView/UserInforEditView')
                    },
                    {
                        path: 'setOfUserView',
                        name: 'SetOfUserView',
                        component: () => import('@/views/AMother/EditView/SetOfUserView')
                    },
                    {
                        path: 'articleEdit',
                        name: 'ArticleEdit',
                        component: () => import('@/views/AMother/EditView/ArticleEditManage')
                    },
                ]
            },
            //首页文章页面
            {
                path:'articleDetail',
                name:'FrontArticleDetail',
                component: ()=> import('@/views/AMother/ArticleDetail'),
            },
            //文章的编写
            {
                path: 'article',
                name: 'Article',
                component:() => import('@/views/AMother/Article')
            }
        ]
    },

    {
        path: '/release',
        name: 'ArticleRelease',
        component: () => import(/* webpackChunkName: "about" */ '../views/AMother/ArticleRelease')
    },


    // 404 page must be placed at the end !!!
    { path: '*', redirect: '/404', hidden: true }
]





const createRouter = () => new Router({
    mode: 'history',
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes,

})


const router = createRouter()


//登录拦截器


export function resetRouter() {
    const newRouter = createRouter()
    router.matcher = newRouter.matcher // reset router

}

export default router
